package jjn.daily;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/8 23:11
 */
public class LeetCode1749 {
    public int maxAbsoluteSum(int[] nums) {
        int positiveSum = 0, negativeSum = 0;
        int positiveMax = 0, negativeMax = 0;
        for (int num : nums) {
            positiveSum += num;
            positiveMax = Math.max(positiveSum, positiveMax);
            positiveSum = Math.max(0, positiveSum);
            negativeSum += num;
            negativeMax = Math.min(negativeSum, negativeMax);
            negativeSum = Math.min(negativeSum, 0);
        }
        return Math.max(positiveMax, -negativeMax);
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int total = scanner.nextInt();
        int[] nums = new int[total];
        for (int i = 0; i < total; i++) {
            nums[i] = scanner.nextInt();
        }
        int maxAbsoluteSum = new LeetCode1749().maxAbsoluteSum(nums);
        System.out.println(maxAbsoluteSum);
    }
}
